package eraserhead.controller;

import org.w3c.dom.Node;

import xml.Message;
import client.IMessageHandler;
import eraserhead.xml.response.AddChoiceResponse;
import eraserhead.xml.response.AddEdgeResponse;
import eraserhead.xml.response.AdminResponse;
import eraserhead.xml.response.CloseResponse;
import eraserhead.xml.response.ConnectResponse;
import eraserhead.xml.response.CreateResponse;
import eraserhead.xml.response.RemoveResponse;
import eraserhead.xml.response.ReportResponse;
import eraserhead.xml.response.SignInResponse;
import eraserhead.xml.response.TurnResponse;

/**
 * Class for handling and dispatching all Message types.
 * @author zhaolongli
 * @author Michael Checca
 */
public class MessageResponseController implements IMessageHandler {

	@Override
	public void process(Message response) {
		Node child = response.contents.getFirstChild();
		String type = child.getLocalName();

		// TODO Somehow add DecisionGUI and Decision model here
		// make them singleton is one way that i can think of
		// and that's how I did in the SignIn GUI and the CreateResponse
		
		if (type.equals("createResponse")) {
			new CreateResponse().process(response);
		} else if (type.equals("connectResponse")) {
			new ConnectResponse().process(response);
		} else if (type.equals("signInResponse")) {
			new SignInResponse().process(response);
		} else if (type.equals("addChoiceResponse")){
			new AddChoiceResponse().process(response);
		} else if (type.equals("addEdgeResponse")){
			new AddEdgeResponse().process(response);
		} else if (type.equals("adminResponse")){
			new AdminResponse().process(response);
		} else if (type.equals("closeResponse")){
			new CloseResponse().process(response);
		} else if (type.equals("removeResponse")){
			new RemoveResponse().process(response);
		} else if (type.equals("reportResponse")){
			new ReportResponse().process(response);
		} else if (type.equals("turnResponse")){
			new TurnResponse().process(response);
		}

		System.out.println("Received:" + response);
	}

}
